
package kayttoliittyma;

import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import opintopaivakirja.Kayttaja;
import opintopaivakirja.Projekti;

/**
 *
 * @author Erkkinuuttinen
 */
public class Aloitussivu extends javax.swing.JPanel {

    /** Creates new form Aloitussivu
     * @param kayttaja
     */
    public Aloitussivu(Kayttaja kayttaja) {
        this.kayttaja = kayttaja;
        top5Projektit = new ArrayList<Projekti>();

        top5Projektit = kayttaja.haeTop5Projektit();

        initComponents();

        // Tarkistetään onko käyttäjällä jo DI-tutkinto -projekti.
        // Jos on niin disabloidaan luo projekti -nappi
        Projekti temp = new Projekti();
        temp.setNimi("DI-tutkinto");
        if (temp.onkoProjekti(kayttaja.getId(), temp)) {
            jButtonDI.setEnabled(false);
        }

        String sp = jLabelViimeisimmatProjektit.getText() + " ";
        ArrayList<Projekti> hauskanimi = new ArrayList<Projekti>();
        hauskanimi = top5Projektit; //kayttaja.haeTop5Projektit();
        if (!hauskanimi.isEmpty()) {
            int koko = hauskanimi.size();

            if (koko > 0 && !(hauskanimi.get(0) == null)) {
                jLabelEka.setText(hauskanimi.get(0).getNimi());
            }
            if (koko > 1 && !(hauskanimi.get(1) == null)) {
                jLabelToka.setText(hauskanimi.get(1).getNimi());
            }
            if (koko > 2 && !(hauskanimi.get(2) == null)) {
                jLabelKolmas.setText(hauskanimi.get(2).getNimi());
            }
            if (koko > 3 && !(hauskanimi.get(3) == null)) {
                jLabelNeljas.setText(hauskanimi.get(3).getNimi());
            }
            if (koko > 4 && !(hauskanimi.get(4) == null)) {
                jLabelViides.setText(hauskanimi.get(4).getNimi());
            }
        }

        jLabelViimeisimmatProjektit.setText(sp);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabelViimeisimmatProjektit = new javax.swing.JLabel();
        jLabelEka = new javax.swing.JLabel();
        jLabelToka = new javax.swing.JLabel();
        jLabelKolmas = new javax.swing.JLabel();
        jLabelNeljas = new javax.swing.JLabel();
        jLabelViides = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        // Code adding the component to the parent container - not shown here
        ImageIcon logo = createImageIcon("images/op_pieni.png");
        jLabelLogo = new javax.swing.JLabel(logo);
        jPanel3 = new javax.swing.JPanel();
        jButtonYleinen = new javax.swing.JButton();
        jButtonMBA = new javax.swing.JButton();
        jButtonDI = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jButtonHae = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jButtonJOKO = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText("Opintopäiväkirja V 1.0.");
        jLabel1.setName("jLabel1"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jLabelViimeisimmatProjektit.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabelViimeisimmatProjektit.setText("5 viimeksi muokattua projektia");
        jLabelViimeisimmatProjektit.setName("jLabelViimeisimmatProjektit"); // NOI18N

        jLabelEka.setName("jLabelEka"); // NOI18N
        jLabelEka.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelEkaMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabelEkaMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabelEkaMouseExited(evt);
            }
        });

        jLabelToka.setName("jLabelToka"); // NOI18N
        jLabelToka.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelTokaMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabelTokaMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabelTokaMouseExited(evt);
            }
        });

        jLabelKolmas.setName("jLabelKolmas"); // NOI18N
        jLabelKolmas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelKolmasMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabelKolmasMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabelKolmasMouseExited(evt);
            }
        });

        jLabelNeljas.setName("jLabelNeljas"); // NOI18N
        jLabelNeljas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelNeljasMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabelNeljasMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabelNeljasMouseExited(evt);
            }
        });

        jLabelViides.setName("jLabelViides"); // NOI18N
        jLabelViides.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelViidesMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabelViidesMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabelViidesMouseExited(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelViimeisimmatProjektit)
                    .addComponent(jLabelEka)
                    .addComponent(jLabelToka)
                    .addComponent(jLabelKolmas)
                    .addComponent(jLabelNeljas)
                    .addComponent(jLabelViides))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelViimeisimmatProjektit)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelEka)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelToka)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelKolmas)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelNeljas)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelViides)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setName("jPanel2"); // NOI18N

        jLabelLogo.setText(null);
        jLabelLogo.setName("jLabelLogo");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelLogo, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelLogo, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setName("jPanel3"); // NOI18N

        jButtonYleinen.setText("Luo yleinen pohja");
        jButtonYleinen.setName("jButtonYleinen"); // NOI18N

        jButtonMBA.setText("Luo MBA tutkinto");
        jButtonMBA.setName("jButtonMBA"); // NOI18N
        jButtonMBA.setPreferredSize(new java.awt.Dimension(117, 23));

        jButtonDI.setText("Luo DI - tutkinto");
        jButtonDI.setName("jButtonDI"); // NOI18N
        jButtonDI.setPreferredSize(new java.awt.Dimension(117, 23));

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel7.setText("Esimerkkiprojektit");
        jLabel7.setName("jLabel7"); // NOI18N

        jButtonHae.setText("Siirry hakuun");
        jButtonHae.setName("jButtonHae"); // NOI18N
        jButtonHae.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonHaeActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setText("Linkki hakuikkunaan");
        jLabel3.setName("jLabel3"); // NOI18N

        jButtonJOKO.setText("Luo JOKO tutkinto");
        jButtonJOKO.setName("jButtonJOKO"); // NOI18N
        jButtonJOKO.setPreferredSize(new java.awt.Dimension(117, 23));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jButtonDI, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                    .addComponent(jButtonMBA, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                    .addComponent(jButtonYleinen, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                    .addComponent(jLabel3)
                    .addComponent(jButtonHae, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                    .addComponent(jButtonJOKO, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonDI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonMBA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonJOKO, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonYleinen)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonHae))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(42, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jLabelEkaMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelEkaMouseEntered
        jLabelEka.setFont(new java.awt.Font("Tahoma", 1, 12));
    }//GEN-LAST:event_jLabelEkaMouseEntered

    private void jLabelEkaMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelEkaMouseExited
        jLabelEka.setFont(new java.awt.Font("Tahoma", 0, 12));
    }//GEN-LAST:event_jLabelEkaMouseExited

    private void jLabelEkaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelEkaMouseClicked

        // 1. paikka taulukossa
        int pid = top5Projektit.get(0).getId();

//        for (int i = 0; i < kayttaja.getProjektit().size(); ++i) {
//            if (kayttaja.getProjektit().get(i).getId() == pid) {
////                TiedotJaMuistiinpanot projekti;
////                try {
////                  new TiedotJaMuistiinpanot(kayttaja, kayttaja.getProjektit(), i);
////                } catch (Throwable ex) {
////                    Logger.getLogger(Aloitussivu.class.getName()).log(Level.SEVERE, null, ex);
////                }
//                //this.setVisible(false);
////                projekti.setVisible(true);
//            }

//        }


    // TODO: ikkunan aukeaminen
    }//GEN-LAST:event_jLabelEkaMouseClicked

    private void jButtonHaeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonHaeActionPerformed

        //new HakuIkkuna(this, rootPaneCheckingEnabled, kayttaja);
        // TODO add your handling code here:
}//GEN-LAST:event_jButtonHaeActionPerformed

    private void jLabelTokaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelTokaMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabelTokaMouseClicked

    private void jLabelTokaMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelTokaMouseEntered
        jLabelToka.setFont(new java.awt.Font("Tahoma", 1, 12));
    }//GEN-LAST:event_jLabelTokaMouseEntered

    private void jLabelTokaMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelTokaMouseExited
        jLabelToka.setFont(new java.awt.Font("Tahoma", 0, 12));
    }//GEN-LAST:event_jLabelTokaMouseExited

    private void jLabelKolmasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelKolmasMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabelKolmasMouseClicked

    private void jLabelKolmasMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelKolmasMouseEntered
        jLabelKolmas.setFont(new java.awt.Font("Tahoma", 1, 12));
    }//GEN-LAST:event_jLabelKolmasMouseEntered

    private void jLabelKolmasMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelKolmasMouseExited
        jLabelKolmas.setFont(new java.awt.Font("Tahoma", 0, 12));
    }//GEN-LAST:event_jLabelKolmasMouseExited

    private void jLabelNeljasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelNeljasMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabelNeljasMouseClicked

    private void jLabelNeljasMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelNeljasMouseEntered
        jLabelNeljas.setFont(new java.awt.Font("Tahoma", 1, 12));
    }//GEN-LAST:event_jLabelNeljasMouseEntered

    private void jLabelNeljasMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelNeljasMouseExited
        jLabelNeljas.setFont(new java.awt.Font("Tahoma", 0, 12));
    }//GEN-LAST:event_jLabelNeljasMouseExited

    private void jLabelViidesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelViidesMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabelViidesMouseClicked

    private void jLabelViidesMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelViidesMouseEntered
        jLabelViides.setFont(new java.awt.Font("Tahoma", 1, 12));
    }//GEN-LAST:event_jLabelViidesMouseEntered

    private void jLabelViidesMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelViidesMouseExited
        jLabelViides.setFont(new java.awt.Font("Tahoma", 0, 12));
    }//GEN-LAST:event_jLabelViidesMouseExited

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton jButtonDI;
    public javax.swing.JButton jButtonHae;
    public javax.swing.JButton jButtonJOKO;
    public javax.swing.JButton jButtonMBA;
    public javax.swing.JButton jButtonYleinen;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    public javax.swing.JLabel jLabelEka;
    public javax.swing.JLabel jLabelKolmas;
    private javax.swing.JLabel jLabelLogo;
    public javax.swing.JLabel jLabelNeljas;
    public javax.swing.JLabel jLabelToka;
    public javax.swing.JLabel jLabelViides;
    private javax.swing.JLabel jLabelViimeisimmatProjektit;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    // End of variables declaration//GEN-END:variables
    /**
     *
     */
    public ArrayList<Projekti> top5Projektit;
    private Kayttaja kayttaja;

    /** Returns an ImageIcon, or null if the path was invalid.
     * @param path polku logolle
     * @return
     */
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = Muutos2.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }

}


